home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / pcl / src-16f.lha / compiler / mips / notes.txt < prev    next >
Encoding:
Text File  |  1991-11-06  |  4.0 KB  |  162 lines

  1.  
  2. ;;; $Header: notes.txt,v 1.2 90/02/07 14:05:49 ram Exp $
  3.  
  4.  
  5.  
  6. Call:
  7.  
  8. There are several different kinds of call, depending on what is going on.
  9.  
  10. The call can be named (i.e. use the symbol-function slot) or through a
  11. function object.
  12.  
  13. The call can pass either a fixed number of args or a variable number of
  14. args.
  15.  
  16. The call can return a fixed number of values, a variable number of values,
  17. or be a tail call.
  18.  
  19.  
  20.  
  21. Register usage at the time of the call:
  22.  
  23. LEXENV:  Holds the lexical environment to use during the call if it's a
  24. closure, or garbage if not.
  25.  
  26. CALL-NAME:  Holds the symbol for a named call and garbage for others.
  27.  
  28. OLD-CONT:  Holds the context pointer that should be restored upon return.
  29.  
  30. A0...An:  Holds the first n+1 args.
  31.  
  32. NARGS:  Holds the number of args, as a fixnum.
  33.  
  34. ARGS:  Holds a pointer to the args.  Note: indexes off of this pointer are
  35. as if all the arguments were stored at it, e.g. the first stack arg is at
  36. ARGS[n] where n is number of register args.  Because of this, ARGS is the
  37. same as the callers CONT (OLD-CONT at the time of the call for non-tail
  38. call).
  39. [RAM: note that this must be set up even when NARGS<=n, since the callee may be
  40. expecting more arguments (due to optionals or a bad call.)  ARGS must be
  41. pointing to some valid chunk of memory, since the callee moves all of the
  42. positional args before checking to see if they are actually supplied.]
  43.  
  44. LRA:  Holds the lisp-return-address object that the call should be returned
  45. to.  Calculated for non-tail call, and left as is for tail call.
  46.  
  47. CSP:  Left as is.  The callee will set this as necessary based on CONT.
  48.  
  49. NSP:  ???
  50. [RAM: will be managed similarly to CSP, i.e. callee has to allocate and is
  51. required to deallocate.]
  52.  
  53. CONT:  The callee's context pointer.  Established as CSP for non-tail call,
  54. and left as is for tail call.
  55.  
  56. CODE:  The function object being called.
  57.  
  58.  
  59.  
  60. Register usage at the time of the return for single value return:
  61.  
  62. A0:  The value.
  63.  
  64. CODE:  The lisp-return-address we returned to.
  65.  
  66. CSP:  Restored from CONT.
  67. [RAM: i.e. stack is guaranteed to be clean.  No SP frobbing is necessary.]
  68.  
  69. CONT:  Restored from OLD-CONT.
  70.  
  71.  
  72. Additional register usage for multiple value return:
  73.  
  74. NARGS:  Number of values being returned.
  75.  
  76. A0...An:  The first n+1 values, or NIL if there are less than n+1 values.
  77.  
  78. ARGS:  Pointer to the rest of the values.  The returnee's CONT.
  79. [RAM: i.e. as with ARGS in call, points n+1 words before the first stack
  80. value.]
  81.  
  82.  
  83. CSP:  CONT + NARGS*4
  84.  
  85.  
  86.  
  87.  
  88. What has to happen for this to work:
  89.  
  90. Caller:
  91.   set NARGS
  92.   set ARGS
  93.   if tail call
  94.     CONT <- OLD-CONT
  95.   else
  96.     calc LRA
  97.     CONT <- CSP
  98.   if named
  99.     set CALL-NAME
  100.   set LEXENV
  101.   set CODE
  102.   calc target addr (CODE + n)
  103.   jr
  104.  
  105. Callee:
  106.   allocate-frame
  107.     emit function header.
  108.     set CSP = CONT + size.
  109.     do something with nsp
  110.   setup-environment
  111.     set CODE = CODE - n
  112.   move-argument
  113.     move stack args from ARGS[n] to CONT[n]
  114.  
  115. Returner:
  116.   known values:
  117.     move-result
  118.       move values from CONT[n] to OLD-CONT[n].
  119.     known-return
  120.       CONT = OLD-CONT
  121.       CODE = LRA
  122.       calc target addr (CODE + n)
  123.       jr
  124.  
  125.   unknown constant values (return VOP):
  126.     nargs = 1 case:
  127.       CSP = CONT
  128.       CONT = OLD-CONT
  129.       CODE = LRA
  130.       calc target addr (CODE + n + 8)
  131.       jr
  132.     nargs != 1 case:
  133.       set NARGS
  134.       nil out unused arg regs
  135.       ARGS = CONT
  136.       CSP = CONT + NARGS * word-bytes
  137.       CONT = OLD-CONT
  138.       CODE = LRA
  139.       calc target addr (CODE + n)
  140.       jr
  141.  
  142.   unknown variable values (return-multiple VOP):
  143.     copy the args from wherever to the top of the stack.
  144. [RAM: I would phrase this "to the beginning of the current (returner's) frame".
  145. They will already be there except with RETURN-MULTIPLE (when they *will* be on
  146. the stack top.)  But then after any copy, we adjust CSP so that the values are
  147. once again on stack top.]
  148.     nil out unused arg regs
  149.     ARGS = CONT
  150.     CSP = CONT + NARGS * word-bytes
  151.     CONT = OLD-CONT
  152.     CODE = LRA
  153.     calc target addr (CODE + n)
  154.     jr
  155.  
  156.  
  157. Returnee:
  158.   want fixed number of values:
  159.  
  160.  
  161.   want variable number of values:
  162.